home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows 95 API Bible
/
Windows 95 API Bible 3 Disc Set.iso
/
Win32 API Bible Book 1 of 3
/
CHAPTE26
/
EX1.C
next >
Wrap
C/C++ Source or Header
|
1995-05-29
|
3KB
|
80 lines
#include <genstub.c>
#define OUR_EXCEPTION 0xE0000000
DWORD TestException(DWORD dwExceptionCodeReceived,
LPEXCEPTION_POINTERS lpExceptionInfo, LPCONTEXT lpContext,
LPEXCEPTION_RECORD lpExceptionRecord, DWORD dwTestException )
{
*lpContext = *lpExceptionInfo->ContextRecord;
*lpExceptionRecord = *lpExceptionInfo->ExceptionRecord;
if ( dwExceptionCodeReceived == dwTestException )
return EXCEPTION_EXECUTE_HANDLER;
else
return EXCEPTION_CONTINUE_SEARCH;
}
LPARAM CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_COMMAND:
{
switch (wParam)
{
case IDM_TEST:
{
char szBuffer[128];
LPCONTEXT lpContext = (LPCONTEXT)
HeapAlloc(GetProcessHeap(), 0, sizeof(CONTEXT));
LPEXCEPTION_RECORD lpExcptRec = (LPEXCEPTION_RECORD)
HeapAlloc(GetProcessHeap(), 0, sizeof(EXCEPTION_RECORD));
// Raise exception try block.
try
{
RaiseException(OUR_EXCEPTION, 0, 0, NULL);
}
except( TestException(GetExceptionCode(), GetExceptionInformation(),
lpContext, lpExcptRec, OUR_EXCEPTION ) )
{
wsprintf( szBuffer, "Our Exception, %x, trapped at %X:%X",
lpExcptRec->ExceptionCode, lpContext->SegCs,
lpContext->Eip );
MessageBox( hWnd, szBuffer, "Exception Handler", MB_OK );
}
try
{
int i = 1;
i = i / 0;
}
finally
{
wsprintf( szBuffer, "Abnormal Termination: %d",
AbnormalTermination() );
MessageBox( hWnd, szBuffer, "Finally Handler", MB_OK );
}
HeapFree( GetProcessHeap(), NULL, lpExcptRec );
HeapFree( GetProcessHeap(), NULL, lpContext );
}
break;
case IDM_EXIT: {
DestroyWindow(hWnd);
}
break;
}
}
break;
default:
return (DefWindowProc(hWnd, uMsg, wParam, lParam));
}
return (NULL);
}